package com.xquant.screen.service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.xquant.screen.mapper.IndexMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author: huaiyu.gao -_- -_-
 * @Date: 2021/4/28 17:34
 */
@Service
public class IndexService {

    @Autowired
    private IndexMapper indexMapper;

    public List selectInfo(Map map){
        List datelist = new ArrayList();
        List datalist = new ArrayList();
        List sumlist = new ArrayList();
        List returnlist = new ArrayList();
        List<Map> mapList = indexMapper.selectInfo(map);
        List<Map> SumList = indexMapper.selectSum(map);
        SumList.stream().forEach(p->{
            p.keySet().stream().forEach(q->{
                if (q.equals("B_ISSUE_NUM")){
                    sumlist.add(p.get(q));
                }
            });
        });
        mapList.stream().forEach(p->{
            p.keySet().stream().forEach(q->{
                if (q.equals("B_ISSUE_NUM")){
                  datalist.add(p.get(q));
                } else if (q.equals("B_ISSUE_DATE")){
                    datelist.add(p.get(q));
                }
            });
        });
        returnlist.add(datelist);
        returnlist.add(datalist);
        returnlist.add(sumlist);
        return returnlist;
    }

    public List selectBond(Map map){
        return indexMapper.selectBond(map);
    }
    public ConcurrentHashMap getActualissueamount(Map map){
        return indexMapper.getActualissueamount(map);
    }
    public ConcurrentHashMap getISSUE_NUM(Map map){
        return indexMapper.getISSUE_NUM(map);
    }

    @DS("oracle2")
    public List selectNews(Map map){
        return indexMapper.selectNews(map);
    }
}
